---
# Copyright 2015, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

- include: "prepare_networking_{{ ansible_os_family | lower }}.yml"

- name: Shut down the network interfaces
  command: "ifdown {{ item.name }}"
  when:
    - network_interfaces | changed or (network_interfaces_multinode is defined and network_interfaces_multinode | changed)
    - item.enabled | default(True)
  with_items:
    - { name: br-mgmt }
    - { name: br-storage }
    - { name: br-vlan }
    - { name: br-vxlan }
    - { name: br-dbaas, enabled: "{{ (bootstrap_host_scenario == 'translations') | bool }}" }
    - { name: br-lbaas, enabled: "{{ (bootstrap_host_scenario in ['translations', 'octavia']) | bool }}" }
  tags:
    - networking-interfaces-stop

- name: Shut down the encapsulation network interfaces
  command: "ifdown {{ item.key }}"
  when:
   - network_interfaces_multinode is defined and network_interfaces_multinode | changed
   - bootstrap_host_encapsulation_enabled | bool
  with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
  tags:
    - networking-interfaces-stop

- name: Start the encapsulation network interfaces
  command: "ifup {{ item.key }}"
  when:
    - network_interfaces_multinode is defined and network_interfaces_multinode | changed
    - bootstrap_host_encapsulation_enabled | bool
  with_dict: "{{ bootstrap_host_encapsulation_interfaces }}"
  tags:
    - networking-interfaces-start

- name: Start the network interfaces
  command: "ifup {{ item.name }}"
  when:
    - network_interfaces | changed
    - item.enabled | default(True)
  with_items:
    - { name: br-mgmt }
    - { name: br-storage }
    - { name: br-vlan }
    - { name: br-vxlan }
    - { name: br-dbaas, enabled: "{{ (bootstrap_host_scenario == 'translations') | bool }}" }
    - { name: br-lbaas, enabled: "{{ (bootstrap_host_scenario in ['translations', 'octavia']) | bool }}" }
  tags:
    - networking-interfaces-start

- name: Updating the facts due to net changes
  setup:
    filter: "ansible_br*"
  tags:
    - networking
